package org.lab.tracecash.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entidad que representa una transaccion de unidades de una cuenta a otra a una determinada fecha (por ejemplo el pago de una factura, sacar dinero del cajero, etc)
 */
@Entity
@Table(name = "tc_transaction")
@SuppressWarnings("serial")
public class Transaction implements Serializable {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Long id;

	@Column(name = "short_desc", length = 255)
	private String desc;

	@Column(name = "long_desc", length = 2048)
	private String longDesc;

	@ManyToOne(cascade = CascadeType.PERSIST)
	@JoinColumn(name = "parent")
	private Transaction parent;

	@ManyToOne
	@JoinColumn(name = "ac_from")
	private Account from;

	@ManyToOne
	@JoinColumn(name = "ac_to")
	private Account to;

	@Temporal(TemporalType.DATE)
	@Column(name = "value_date")
	private Date valueDate;

	@Column(name = "amount", precision = 18, scale = 5, nullable = false)
	private BigDecimal amount;

	// TODO no me gusta! Habria que tener a lo mejor varios estados para marcar con flags a la entidad
	@Column(name = "checked")
	private Boolean checked;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getLongDesc() {
		return longDesc;
	}

	public void setLongDesc(String longDesc) {
		this.longDesc = longDesc;
	}

	public Account getFrom() {
		return from;
	}

	public void setFrom(Account from) {
		this.from = from;
	}

	public Account getTo() {
		return to;
	}

	public void setTo(Account to) {
		this.to = to;
	}

	public Date getValueDate() {
		return valueDate;
	}

	public void setValueDate(Date valueDate) {
		this.valueDate = valueDate;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}

	@Override
	public String toString() {
		return "Transaction [desc=" + desc + ", from=" + from + ", to=" + to + ", valueDate=" + valueDate + ", amount=" + amount + "]";
	}
}
